//
//  HBUBoxAlertView.m
//  BlocksKit
//
//  Created by 韩冰 on 2017/11/27.
//

#import "HBUBoxAlertView.h"
#import "UIColor+Extension.h"
#import "HBCommon.H"
#import "UIImage+Extension.h"



@interface HBUBoxAlertView ()

@property (nonatomic, strong)UIImageView *imageView;
@property (nonatomic, strong)UILabel *tipOneLabel;
@property (nonatomic, strong)UILabel *uboxLabel;
@property (nonatomic, strong)UILabel *tipTwoLabel;
@property (nonatomic, strong)UILabel *airLabel;
@property (nonatomic, strong)UIButton *sureButton;
@property (nonatomic, strong)UIButton *cancleButton;
@property (nonatomic, copy)NSString *ubName;
@property (nonatomic, copy)NSString *airName;
@end

@implementation HBUBoxAlertView
+ (HBUBoxAlertView *)createAlertWithU_BoxName:(NSString *)ubName withAirName:(NSString *)airName handleSure:(SureBlock)sureHandle withCancle:(CancleBlock)cancleHandle{
    HBUBoxAlertView *alertView = [[HBUBoxAlertView alloc]initWithU_BoxName:ubName withAirName:airName];
    alertView.sureBlock = ^{
        if (sureHandle) {
            sureHandle();
        }
    };
    alertView.cancleBlock  = ^{
        if (cancleHandle) {
            cancleHandle();
        }
    };
    [alertView show];
    return alertView;
}
- (instancetype)initWithU_BoxName:(NSString *)ubName withAirName:(NSString *)airName
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 5.0;
        self.layer.masksToBounds = YES;
        self.ubName = ubName;
        self.airName = airName;
        self.frame = CGRectMake(60, self.center.y - 60,SCREEN_WIDTH - 120 , 150);
        [self setUpSubViews];
    }
    return self;
}
- (void)setUpSubViews{
    [self addSubview:self.imageView];
    [self addSubview:self.tipOneLabel];
    [self addSubview:self.tipTwoLabel];
    [self addSubview:self.uboxLabel];
    [self addSubview:self.airLabel];
    [self addSubview:self.sureButton];
    [self addSubview:self.cancleButton];
    self.imageView.frame = CGRectMake((self.width/2.0) - 33, 14, 66, 66);
    self.tipOneLabel.frame = CGRectMake(12, self.imageView.bottom + 12, self.width-24, 17);
    self.uboxLabel.frame = CGRectMake(12, self.tipOneLabel.bottom + 10, self.width-24, 17);
    self.tipTwoLabel.frame = CGRectMake(12, self.uboxLabel.bottom + 10, self.width-24, 16);
    self.airLabel.frame = CGRectMake(12, self.tipTwoLabel.bottom + 4, self.width-24, 16);
    self.sureButton.frame = CGRectMake(12, self.airLabel.bottom + 16, (self.width/2.0) - 24, 40);
    self.cancleButton.frame = CGRectMake(self.sureButton.right + 24, self.airLabel.bottom + 16, (self.width/2.0) - 24, 40);
    self.frame = CGRectMake(60, self.center.y - 60,SCREEN_WIDTH - 120 , self.cancleButton.bottom + 16);
//    self.centerY = SCREEN_HEIGHT/2.0 -20;
    self.uboxLabel.text = self.ubName;
    self.airLabel.text = self.airName;
}


- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.image = [UIImage hb_imagePathWithName:@"device_gps_unbind" bundle:@"XFDCommon" targetClass:[self class]];
    }
    return _imageView;
}
- (UILabel *)tipOneLabel{
    if (!_tipOneLabel) {
        _tipOneLabel = [[UILabel alloc]init];
        _tipOneLabel.textAlignment = NSTextAlignmentCenter;
        _tipOneLabel.text= @"确定要解绑?";
        _tipOneLabel.textColor = [UIColor HB_ColorWithHexString:@"#3eabf9"];
        _tipOneLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _tipOneLabel;
}
- (UILabel *)tipTwoLabel{
    if (!_tipTwoLabel) {
        _tipTwoLabel = [[UILabel alloc]init];
        _tipTwoLabel.textAlignment = NSTextAlignmentCenter;
        _tipTwoLabel.text= @"已绑定到无人机";
        _tipTwoLabel.textColor = [UIColor HB_ColorWithHexString:@"#898888"];
        _tipTwoLabel.font = [UIFont systemFontOfSize:14];
    }
    return _tipTwoLabel;
}
- (UILabel *)uboxLabel{
    if (!_uboxLabel) {
        _uboxLabel = [[UILabel alloc]init];
        _uboxLabel.textAlignment = NSTextAlignmentCenter;
        _uboxLabel.textColor = [UIColor blackColor];
        _uboxLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _uboxLabel;
}
- (UILabel *)airLabel{
    if (!_airLabel) {
        _airLabel = [[UILabel alloc]init];
        _airLabel.textAlignment = NSTextAlignmentCenter;
        _airLabel.textColor = [UIColor blackColor];
        _airLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _airLabel;
}
- (UIButton *)sureButton{
    if (!_sureButton) {
        _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _sureButton.backgroundColor = [UIColor HB_ColorWithHexString:@"#3eabf9"];
        [_sureButton setTitle:@"确定" forState:UIControlStateNormal];
        [_sureButton addTarget:self action:@selector(sureAction) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
        _sureButton.layer.cornerRadius = 5.0;
        _sureButton.layer.masksToBounds = YES;
    }
    return _sureButton;
}
- (UIButton *)cancleButton{
    if (!_cancleButton) {
        _cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancleButton setTitleColor:[UIColor HB_ColorWithHexString:@"#686868"] forState:UIControlStateNormal];
        _cancleButton.backgroundColor = [UIColor HB_ColorWithHexString:@"#ededed"];
        [_cancleButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cancleButton addTarget:self action:@selector(cancleAction) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
        _cancleButton.layer.cornerRadius = 5.0;
        _cancleButton.layer.masksToBounds = YES;
    }
    return _cancleButton;
}

- (void)cancleAction{
    if (self.cancleBlock) {
        self.cancleBlock();
    }
    [self hide];
}
- (void)sureAction{
    if (self.sureBlock) {
        self.sureBlock();
    }
    [self hide];
}
@end
